package org.veridiandynamics.client.view;

import java.awt.CardLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.veridiandynamics.server.dao.Queryprocessor;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

/**
 * @author Talia
 * 
 * This class creates the panel where system admins can set passwords in text fields.
 *
 */
public class SetPasswords extends JPanel 
{
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private CardLayout c1;
	private Container container;
	private JButton btnSubmit;
	private JTextField userField;
	private JTextField passField;
	private JTextField userField2;

	/**
	 * The constructor for the panel.
	 * Create the panel.

	 * @param c1 card layout
	 * @param container the container used
	 */
	public SetPasswords(final CardLayout c1, final Container container)
	{
		this.c1 = c1;
		this.container = container;
		setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("max(79dlu;default)"),
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,},
				new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));

		JLabel lblSetPassword = new JLabel("1.  Set password:");
		add(lblSetPassword, "4, 4");

		JLabel lblEnterUsername = new JLabel("Enter username:");
		add(lblEnterUsername, "4, 6");

		JLabel lblEnterPassword = new JLabel("Enter password:");
		add(lblEnterPassword, "8, 6");

		userField = new JTextField();
		add(userField, "4, 8, fill, default");
		userField.setColumns(10);

		passField = new JTextField();
		add(passField, "8, 8, fill, default");
		passField.setColumns(10);

		JLabel label = new JLabel("                      ");
		add(label, "14, 8");

		btnSubmit = new JButton("Submit");
		btnSubmit.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				String username = userField.getText();
				String password = passField.getText();
				Queryprocessor.setResetPassword(username, password);
			}
		});
		add(btnSubmit, "12, 10");

		JLabel lblResetPassword = new JLabel("2.  Reset password:");
		add(lblResetPassword, "4, 14");

		JLabel lblEnterUsername_1 = new JLabel("Enter username:");
		add(lblEnterUsername_1, "4, 16");

		userField2 = new JTextField();
		add(userField2, "4, 18, fill, default");
		userField2.setColumns(10);

		JButton btnReset = new JButton("Reset");
		btnReset.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				String username = userField2.getText();
				Queryprocessor.setResetPassword(username, "");
			}
		});
		add(btnReset, "12, 18");

		JButton btnBack = new JButton("Back");
		btnBack.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				c1.first(container);
			}
		});
		add(btnBack, "12, 22");

		}

	}
